package com.twq.oo.packandimpo

/**
 * Created by tangweiqun on 2017/12/1.
 */
object ImportTest {

  def main(args: Array[String]): Unit = {

    //访问Fruit
    import com.twq.fruit.Fruit

    //访问com.twq.fruit中所有的成员
    import com.twq.fruit._
    //访问Fruits中的所有成员
    import com.twq.fruit.Fruits._
    menu

    def showFruit(fruit: Fruit) = {
      //导入一个对象的所有的成员
      import fruit._
      println(name + "s are " + color)
    }


    import Fruits.{Apple, Orange}

    import Fruits.{Apple => McIntosh, Orange} //Apple重命名为McIntosh
    McIntosh.name
    import java.sql.{Date => SDate}
    import java.util.{Date => uDate}
    import java.{sql => S}
    val data: S.Date = new SDate(System.currentTimeMillis())
    new uDate

    import Fruits.{_}
    import Fruits.{Apple => McIntosh, _} //导入Fruits中的所有成员，并且将Apple重命名为McIntosh
    import Fruits.{Pear => _, _} //导入Fruits中的所有成员，除了Pear

  }

}

package com.twq.fruit {

  abstract class Fruit(
                        val name: String,
                        val color: String
                      )

  object Fruits {

    object Apple extends Fruit("apple", "red")

    object Orange extends Fruit("orange", "orange")

    object Pear extends Fruit("pear", "yellowish")

    val menu = List(Apple, Orange, Pear)
  }

}


